package xin.yangshuai.basic01.download;

/**
 * Result
 *
 * @author shuai
 * @date 2019/6/10
 */
public class Result<T> {
    private int code;
    private String message;
    private Object data;

    public Result() {
    }

    private Result(int code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public static <T> Result<T> success() {
        return new Result<>(Constant.SUCCESS_CODE, Constant.SUCCESS_MESSAGE, null);
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(Constant.SUCCESS_CODE, Constant.SUCCESS_MESSAGE, data);
    }

    public static <T> Result<T> success(String message, T data) {
        return new Result<>(Constant.SUCCESS_CODE, message, data);
    }

    public static Result error() {
        return new Result<>(Constant.ERROR_CODE, Constant.ERROR_MESSAGE, null);
    }

    public static Result error(String message) {
        return new Result<>(Constant.ERROR_CODE, message, null);
    }
}
